﻿@using System.Data;
@using GatewayServer.Common;
@using UtilsBase;
@{
    ViewBag.PageTitle = "洪峰智能";

    Layout = "~/Views/Shared/PageTemplate.cshtml";
}

<script>
    $(document).ready(function () {

        if ("@(ViewBag.order)" == "upd") {
            getEdit("@(ViewBag.edit_guid)");
        }
        getLanguages();
        getLanguagesConfigItemsForDataTable();
    });

    function getEdit(dguid) {
        $.post("getConfig", { "flag": Math.random(), guid: dguid }, function (result) {
            var myobj = (result.data);
            $("#lp_name").val(myobj.lp_name);
        });
    }

    function saveAll() {
        $("#labelmsg").text("");
        var data = $("#addForm").serializeArray(); //自动将form表单封装成json
        $.post("saveAll", data, function (result) {
            var jsonresult = (result);

            if (jsonresult.respCode == "200") {
                $("#labelmsg").text("操作完成");
                // window.location.href = "list";
                // window.history.back();
                // alert("保存成功");

                getLanguagesConfigItemsForDataTable();
            }
            else {
                alert(jsonresult.respMsg);
                return;
            }
        });
    }

    function getLanguages() {
        $("#l_guid").empty();
        $("#l_guid").append("<option value=''  selected='selected'>请选择</option>");
        $.post("getLanguages", { "flag": Math.random() }, function (result) {
            var myobj = (result.data);
            for (var i = myobj.length - 1; i >= 0; i--) {
                $("#l_guid").prepend("<option value='" + myobj[i].l_guid + "'>" + myobj[i].l_code + "-" + myobj[i].l_name + "</option>")
            }


            for (var i = 0; i < document.getElementById("l_guid").options.length; i++) {
                if (document.getElementById("l_guid").options[i].value == $("#hid_l_guid").val()) {
                    document.getElementById("l_guid").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("l_guid").options[i].selected = false;

                }
            }
        });
    }

    function getLanguagesConfigItemsForDataTable() {
        $.post("getLanguagesConfigItemsForDataTable", { "flag": Math.random(), guid: $("#edit_guid").val(), type: "main" }, function (result) {
            var pagedata = (result.data);
            rowcount = 0;
            var htmlstr = "";
            htmlstr = htmlstr + "<tr class='plainItemTRTitle'>";
            htmlstr = htmlstr + "<td >序号</td >";
            htmlstr = htmlstr + "<td >语言</td >";
            htmlstr = htmlstr + "<td >语言编号</td >";
            htmlstr = htmlstr + "<td >内容</td >";
            htmlstr = htmlstr + "<td >时间</td >";
            htmlstr = htmlstr + "<td >操作</td >";
            htmlstr = htmlstr + "</tr >";
            document.getElementById("datalist").innerHTML = "";
            if (pagedata != null && pagedata.length > 0) {
                for (var i = 0; i < pagedata.length; i++) {
                    rowcount = i + 1;
                    htmlstr = htmlstr + "<tr>";
                    htmlstr = htmlstr + "<td >" + rowcount + "</td >";
                    htmlstr = htmlstr + "<td >" + pagedata[i].l_name + "</td >";
                    htmlstr = htmlstr + "<td >" + pagedata[i].l_code + "</td >";
                    htmlstr = htmlstr + "<td >" + pagedata[i].lpi_content + "</td >";
                    htmlstr = htmlstr + "<td >" + pagedata[i].lpi_addtime + "</td >";
                    htmlstr = htmlstr + "<td ><a href=\"javascript:del('" + pagedata[i].lpi_guid + "')\">删除</a> </td >";
                    htmlstr = htmlstr + "</tr >";

                }
                document.getElementById("datalist").innerHTML = htmlstr;
            }
        });

    }

    function del(guid) {
        var data = $("#addForm").serializeArray(); //自动将form表单封装成json
        $.post("delitem?guid=" + guid, data, function (result) {
            var jsonresult = (result);
            if (jsonresult.respCode == "200") {
                getLanguagesConfigItemsForDataTable();
            }
            else {
                alert(jsonresult.respMsg);
                return;
            }
        });

    }
</script>

<style>

    .plainItemTable td {
        line-height: 30px;
        min-width: 150px;
    }

    #pagelist_follow {
        width: 100%;
    }

    #pagelist_main {
        width: 100%;
    }

    .kv-item label {
        width: 150px;
    }
</style>
<div id="saper-container">
    <form id="addForm" name="addForm" action="list" method="post">
        <input type="hidden" name="edit_guid" id="edit_guid" value="@ViewBag.edit_guid" />
        <input type="hidden" name="lp_p_guid" id="lp_p_guid" value="@ViewBag.pGuid" />
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>语言添加</h2>
            </div>
            <div class="subfiled-content">

                <div id="" title="添加/编辑">
                    <form action="" name="addForm" id="addForm" method="post">

                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>名称：</label>
                            <div class="kv-item-content">
                                <input type="text" name="lp_name" id="lp_name" placeholder="名称" />

                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>语言：</label>
                            <div class="kv-item-content">
                                <select id="l_guid" name="l_guid" style="width:130px;">
                                    <option value="">请选择</option>
                                </select>
                                <input type="hidden" name="hid_l_guid" id="hid_l_guid" value="" />
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>内容：</label>
                            <div class="kv-item-content">
                                <input type="text" name="lpi_content" id="lpi_content" placeholder="内容" />

                            </div>
                        </div>
                        <div>
                            <hr />
                            <table id="datalist" class="plainItemTable"></table>
                        </div>
                        <div style="margin:0 auto;width:150px;">

                            <input type="button" id="save" name="save" value="保存" onclick="javascript:saveAll()" />
                            &nbsp;&nbsp; <input type="button" id="but_back1" name="but_back1" value="返回" onclick="javascript:window.history.back()" />
                        </div>
                        <div style="margin:0 auto;width:150px;">
                            <label id="labelmsg"></label>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div id="saper-ft"></div>
    </form>
</div>

